home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / d_pc.c < prev    next >
C/C++ Source or Header  |  1995-02-07  |  32KB  |  1,224 lines

  1. /*--------------------------------------------------------------*/
  2. /*  IBM PC Driver 1.0 (TURBO  C) , for GLE V3.0     */
  3. /*--------------------------------------------------------------*/
  4.  
  5. /*---------------------------------------------------------------------------*/
  6. #include "all.h"
  7. #include <bios.h>
  8. #include <math.h>
  9. #include "core.h"
  10. #include "mygraph.h"
  11. #include "mydev.h"
  12.  
  13. #ifdef __GNUC__     /* a.r. */
  14. #  ifndef __linux__
  15. #    include <pc.h>
  16. #  endif
  17. #  include <grx.h>
  18. #  include <bccgrx.h>
  19. #else
  20. #  include <conio.h>
  21. #  include <graphics.h>
  22. #endif
  23.  
  24. int ingraphmode;
  25. extern int gunit;
  26. extern struct gmodel g;
  27. /*---------------------------------------------------------------------------*/
  28. #define pi 3.141592653
  29. #define true (!false)
  30. #define BLACKANDWHITE 1
  31. #define false 0
  32. #define dbg if ((gle_debug & 64)>0)
  33. #define stop if ((gle_debug & 128)>0) return
  34. extern int gle_debug;
  35. int incap=true;
  36.  
  37.  
  38. #ifndef __linux__       /* a.r. */
  39. int getch(void);
  40. int kbhit(void);
  41. #endif
  42. #ifdef __linux__
  43. #undef kbhit
  44. #define getch getchar
  45. #endif
  46.  
  47. int d_prompts(void);
  48. /*---------------------------------------------------------------------------*/
  49. /* The global variables for the PC screen driver */
  50. /*-----------------------------------------------*/
  51.  
  52. int i,l,j,ix,iy;
  53. double f;
  54.  
  55.  
  56. #define gerr() i = graphresult(); if (i!=0) printf("Graph error: %s \n",grapherrormsg(i));
  57. /*
  58. #define xsizecm 21.0
  59. #define ysizecm 18.0
  60. */
  61. #define xsizecm 32.0
  62. #define ysizecm 24.0
  63.  
  64. #define sx(v) ( (int) ((v) * d_xscale)+1)
  65. #define sy(v) ( d_maxy - ((int) ((v) * d_yscale)))
  66. #define rx(v) ( (int) ((v) * d_xscale)+1)
  67. #define ry(v) ( d_maxy - ((int) ((v) * d_yscale)))
  68. #define textmode() {getch(); restorecrtmode();}
  69. #define graphmode() {getch(); setgraphmode(d_graphmode);}
  70. #define gon  if ((gle_debug & 256) > 0) graphmode()
  71. #define goff if ((gle_debug & 256) > 0) textmode()
  72.  
  73. double d_scale, d_xscale, d_yscale;
  74. int d_graphmode;
  75. int d_fillstyle,d_fillcolor;
  76. int d_lstyle,d_lwidth,d_pat;
  77. int d_maxy;
  78.  
  79. int d_zzline(double cx,double cy,double zx,double zy);
  80. int addline(char *s);
  81.  
  82. int getwhite(void);
  83. int getwhite()
  84. {
  85.     int i;
  86.     i = getmaxcolor();
  87.     if (i>15) i = 15;
  88.     return i;
  89. }
  90. d_devcmd(char *s)
  91. {}
  92.  
  93. int undxy(int dx, int dy, double *x, double *y);
  94. undxy(int dx, int dy, double *x, double *y)
  95. {
  96.     double ddx,ddy;
  97.     char buff[80];
  98.     ddx = (dx)/d_xscale;
  99.     ddy = (dy - d_maxy) / -d_yscale;
  100.     g_undev(ddx,ddy,x,y);
  101. }
  102. dxy(double x, double y, int *dx, int *dy)
  103. {
  104.     static double fx,fy;
  105.     g_dev(x,y,&fx,&fy);
  106.     *dx = sx(fx);
  107.     *dy = sy(fy);
  108. }
  109. rxy(double x, double y, int *dx, int *dy)
  110. {
  111.     static double fx,fy,zx,zy;
  112.     g_dev(x,y,&fx,&fy);
  113.     g_dev(0.0,0.0,&zx,&zy);
  114.     *dx = (int) ( (fx-zx) * d_xscale +1);
  115.     *dy = (int) ( (fy-zy) * d_yscale);
  116. }
  117. /*---------------------------------------------------------------------------*/
  118. d_dfont(char *c)
  119. {
  120.     /* only used for the DFONT driver which builds fonts */
  121. }
  122. /*---------------------------------------------------------------------------*/
  123. static char lastline[80];
  124. d_message(char *s)
  125. {
  126.     static int single_step;
  127.     int oldcolor,oldx,oldy;
  128.     if (ingraphmode) {
  129.         oldx = getx(); oldy = gety();
  130.         oldcolor = getcolor();
  131.         setfillstyle(1,BLACK);
  132.         setcolor(WHITE);
  133.         bar(1,getmaxy()-19,getmaxx(),getmaxy());
  134.         settextstyle(0,0,0);
  135.         settextjustify(LEFT_TEXT,BOTTOM_TEXT);
  136.         moveto(4,getmaxy()-10);
  137.         if (strlen(lastline)>0) outtext(lastline);
  138.         moveto(4,getmaxy()-2);
  139.         outtext(s);
  140.         ncpy(lastline,s,78);
  141.         setcolor(oldcolor);
  142.         setfillstyle(d_fillstyle,d_fillcolor);
  143.         moveto(oldx,oldy);
  144.         if (single_step) {
  145.             if (getch()=='g') single_step = false;
  146.         }
  147.         if (kbhit()) {
  148.             if ((bioskey(1) & 0xff) != 27) {
  149.              if (getch()=='s') single_step = true;
  150.              while (kbhit()) getch();
  151.              getch();
  152.             }
  153.         }
  154.     } else {
  155.         printf("%s\n",s);
  156.     }
  157. }
  158. /*---------------------------------------------------------------------------*/
  159. d_source(char *s)
  160. {
  161.     s=s;
  162. }
  163. /*---------------------------------------------------------------------------*/
  164. d_get_type(char *t)
  165. {
  166.     strcpy(t,"INTERACTIVE, PC");
  167. }
  168. /*---------------------------------------------------------------------------*/
  169. d_set_path(int onoff)
  170. {}
  171. /*---------------------------------------------------------------------------*/
  172. d_newpath()
  173. {
  174. }
  175. int svga_mode=grError;
  176. int huge detect_svga()
  177. {
  178.   gprint("Loading USER BGI driver \n");
  179.   return svga_mode;
  180. }
  181. void add_svga(void)
  182. {
  183.     int g_error;
  184.     char *s,buff[80],sname[40];
  185.     s = getenv("GLE_ADDBGI");
  186.     if (s==NULL) return;
  187.     strcpy(buff,s);
  188.     s = strtok(buff," .");
  189.     if (s==NULL) {gprint("Expecting mode.name, e.g. 3.svga256,  found {%s} \n",buff); return;}
  190.     svga_mode = atoi(s);
  191.     s = strtok(NULL," .");
  192.     if (s==NULL) {gprint("Expecting 'mode.name' , e.g. 3.svga256,  found {%s} \n",buff); return;}
  193.     strcpy(sname,s);
  194. #ifndef __GNUC__         /* no BGI a.r. */ 
  195.     installuserdriver(sname,detect_svga);
  196. #endif
  197.     g_error = graphresult();
  198.     if (g_error<0) {
  199.         gprint("InstallUserDriver error %s\n",grapherrormsg(g_error));
  200.         text_inkey();
  201.     }
  202. }
  203.  
  204. /*---------------------------------------------------------------------------*/
  205. char *bgidir(void);
  206. d_open(double width, double height)
  207. {
  208.     static int g_driver,g_error;
  209.     double f;
  210.     static int doneopen;
  211.  
  212.     if (!doneopen) {
  213. #ifndef DJ  /* a.r. */
  214.         add_svga();
  215. #endif
  216.         doneopen = true;
  217.  
  218.         /* detectgraph(&g_driver, &d_graphmode);
  219.         if (g_driver<0) {
  220.             printf("No graphics hardware detected !!!!! \n");
  221.             gle_abort("Could not load BGI graphics\n");
  222.         }  */
  223.         g_driver = DETECT;
  224. #ifndef __GNUC__    /* a.r. */
  225.         initgraph(&g_driver,&d_graphmode,bgidir());
  226. #else
  227.                 {
  228.                 char *buffa = getenv("GLE32WIDTH");
  229.                 char *buffb = getenv("GLE32HEIGHT");
  230.                 char *buffc = getenv("GLE32COLORS");
  231.                 if ( ( buffa != NULL ) && ( buffb != NULL ) && ( buffc != NULL ) )
  232.                   {
  233.                         g_driver = DETECT;
  234.                         set_BGI_mode_whc(&g_driver, &d_graphmode, atoi(buffa), atoi(buffb), atoi(buffc));
  235.                         initgraph(&g_driver,&d_graphmode,getenv("GLE32FONT"));
  236.                   }
  237.                 else
  238.                   { 
  239.                         detectgraph(&g_driver, &d_graphmode);
  240.                         initgraph(&g_driver,&d_graphmode,getenv("GLE32FONT"));
  241.                   }  
  242.                 }
  243. #endif                
  244.     } else  {
  245.         setgraphmode(d_graphmode);
  246.     }
  247.     g_error = graphresult();
  248.     if (g_error<0) {
  249.         printf("Init graph error %s\n",grapherrormsg(g_error));
  250.         ingraphmode = false; text_inkey(); gle_abort("Init graph error\n");
  251.     }
  252. #ifndef __GNUC__     /* a.r. */ 
  253.     if (g_driver==HERCMONO) pokeb(0x40,0x49,6); /* this makes mouse work on herc card */
  254. #endif
  255.     ingraphmode = true;
  256.     /* Get largest rectangle we can fit on the screen */
  257.     d_scale = xsizecm / width;
  258.     f = ysizecm / height;
  259.     if (f<d_scale) d_scale = f;
  260.  
  261.     d_xscale = d_scale * (getmaxx()-2) / xsizecm; /* Device Scale X, Device Scale y */
  262.     d_yscale = d_scale * (getmaxy()-22) / ysizecm;
  263.     d_maxy = getmaxy()-21;
  264.     g.userwidth = width;
  265.     g.userheight = height;
  266. }
  267. /*---------------------------------------------------------------------------*/
  268. d_tidyup()
  269. {
  270.     if (ingraphmode) {
  271.         gprint("AARRRrrrrgg,  Watch out I'm dying!!!\n");
  272.         d_close();
  273.     }
  274. }
  275. void mouseloc(int column,int  row);             /* set location of mouse cursor */
  276. int draw_boxline(int d_imde,double x1,double y1,double x2,double y2);
  277. int d_get_click(double *x, double *y, int *click);
  278. int d_get_point(double *x, double *y, int *click);
  279. void mousecursor( int toggle);
  280. int cross_hair(double x, double y);
  281. int mousecheck(void);
  282. double mouse_x,mouse_y,gridstep;
  283. int boxed_text,ismouse;
  284. int d_imde;
  285. double d_mousex,d_mousey;
  286.  
  287.  
  288. int gridit(double *x,double *y);
  289. gridit(double *x,double *y)
  290. {
  291.     *x = floor(*x/gridstep + .5) * gridstep;
  292.     *y = floor(*y/gridstep + .5) * gridstep;
  293. }
  294. int d_prompts(void)
  295. {
  296.      if (d_imde==1) d_message("Click on position for TEXT");
  297.      if (d_imde==2) d_message("Click on position for LINE");
  298.      if (d_imde==3) d_message("Click on position for BOX");
  299.      d_message("t=text l=line b=box o=bOxed_text c=Click u=penUp f=finer g=greater ESC=Exit");
  300. }
  301. d_cursor_toggle(void)
  302. {
  303.     static int onoff=0;
  304.     onoff = !onoff;
  305.     setcolor(getwhite());
  306.     setwritemode(XOR_PUT);
  307.     if (ismouse) mousecursor(onoff); else cross_hair(d_mousex,d_mousey);
  308.     setcolor(0);
  309.     setwritemode(COPY_PUT);
  310. }
  311. d_xor(void)
  312. {
  313.     setcolor(getwhite());
  314.     setwritemode(XOR_PUT);
  315. }
  316. wait_for_return()
  317. {
  318.     int exitlp=false,click=0,clickex=0,oldmode;
  319.     double x1,y1,x2,y2,nx,ny;
  320.     char buff1[90],buff2[90];
  321. /* valid commands are */
  322. /* t = text, l = line, u=penup, b=box, o=bOxed text, f = finer, g = greater */
  323.     d_imde = 2;
  324.     if (d_mousex==0) {
  325.         d_mousex = g.userwidth/2;
  326.         d_mousey = g.userheight/2;
  327.     }
  328.     if (mousecheck()) ismouse = true;
  329.     if (!ismouse) gridstep = 1;
  330.     if (gridstep==0) gridstep = .1;
  331.     d_cursor_toggle();
  332.     for (;;) {
  333.      d_prompts();
  334.      oldmode = d_imde;
  335.      d_get_click(&x1,&y1,&click); if (click==3) goto aborting;
  336.      if (oldmode!=d_imde) goto next_one;
  337.      gridit(&x1,&y1);
  338.      if (d_imde==1) {
  339.         d_message("Enter the text at the top of the screen");
  340.         d_get_line(buff1,&click);
  341.         if (click==3) goto next_one;
  342.         sprintf(buff2,"amove %g %g ",x1,y1); addline(buff2);
  343.         if (boxed_text) addline("begin box add .2");
  344.         sprintf(buff2,"text %s",buff1);
  345.         addline(buff2);
  346.         if (boxed_text) addline("end box");
  347.         g_move(x1,y1);
  348.         g_text(buff1);
  349.         if (d_imde==1) d_imde = 2;
  350.         goto next_one;
  351.      }
  352.      sprintf(buff1,"amove %g %g",x1,y1); addline(buff1);
  353. poly:    d_xor();
  354.      draw_boxline(d_imde,x1,y1,x1,y1);
  355.      x2 = x1; y2 = y1;
  356.      if (d_imde==2 || d_imde==3) {
  357.       oldmode = d_imde;
  358.       for (click=0;click==0 && (d_imde==oldmode);) {
  359.         d_get_point(&nx,&ny,&click);
  360.         if (x2!=nx || y2!=ny) {
  361.           d_cursor_toggle();
  362.           d_xor();
  363.           draw_boxline(oldmode,x1,y1,x2,y2);
  364.           draw_boxline(oldmode,x1,y1,nx,ny);
  365.           d_cursor_toggle();
  366.         }
  367.         delay(10);
  368.         x2 = nx; y2 = ny;
  369.       }
  370.       d_cursor_toggle();
  371.       d_xor();
  372.       draw_boxline(oldmode,x1,y1,nx,ny);
  373.       if (click==1 && d_imde==oldmode) {
  374.         gridit(&x2,&y2);
  375.         setcolor(0);
  376.         setwritemode(COPY_PUT);
  377.         draw_boxline(d_imde,x1,y1,x2,y2);
  378.         if (d_imde==2) {
  379.             sprintf(buff1,"rline %g %g",x2-x1,y2-y1); addline(buff1);
  380.             x1 = x2; y1 = y2;
  381.             d_cursor_toggle();
  382.             if (click==1) goto poly;
  383.         }
  384.         if (d_imde==3) {
  385.             sprintf(buff1,"box %g %g ",x2-x1,y2-y1); addline(buff1);
  386.         }
  387.       }
  388.       d_cursor_toggle();
  389.      }
  390. next_one:;
  391.     setcolor(0);
  392.     setwritemode(COPY_PUT);
  393.     }
  394. aborting:;
  395.     d_cursor_toggle();
  396. }
  397. draw_boxline(int d_imde,double x1,double y1,double x2,double y2)
  398. {
  399.     if (d_imde==2) {
  400.         g_move(x1,y1);
  401.         g_line(x2,y2);
  402.     } else {
  403.         g_move(x1,y1);
  404.         g_box_stroke(x1,y1,x2,y2);
  405.     }
  406. }
  407. d_get_click(double *x, double *y, int *click)
  408. {
  409.     for (;;) {
  410.      d_get_point(x,y,click);
  411.      if (*click>0) return;
  412.      delay(10);
  413.     }
  414. }
  415. #include "edt.h"
  416. int ddgets(char *s);
  417. d_get_line(char *s,int *click)
  418. {
  419.     if (ddgets(s)) *click = 3;
  420.     else *click = 0;
  421. }
  422. ddgets(char *s)
  423. {
  424.     int c,cx=0;
  425.     char mbuff[80];
  426.     *s = 0;
  427.     bottom_line(s);
  428.     for (;;) {
  429.      c = text_inkey();
  430.      switch (c) {
  431.        case eescape: /* ESCAPE */
  432.        case equit: /* control c */
  433.         return true;
  434.       case ereturn: /* carriage return */
  435.         return false;
  436.       case edelete: /* delete */
  437.         if (strlen(s)==0) break;
  438.         if (cx<1) break;
  439.         ncpy(mbuff,s,cx-1);
  440.         strcat(mbuff,s + cx);
  441.         strcpy(s,mbuff);
  442.         cx--;
  443.         bottom_line(s);
  444.         break;
  445.       default: /* normal key */
  446.         if (c<26  && c!=9) {fner("Key has no affect"); break;}
  447.         if (c>200)  fner("Unimplemented command");
  448.         else {
  449.             ncpy(mbuff,s,cx);
  450.             mbuff[cx] = c; mbuff[cx+1] = 0;
  451.             strcat(mbuff,s + cx);
  452.             strcpy(s,mbuff);
  453.             bottom_line(s);
  454.             cx++;
  455.         }
  456.         break;
  457.        }
  458.      }
  459. }
  460. bottom_line(char *s)
  461. {
  462.     setfillstyle(1,BLACK);
  463.     setcolor(WHITE);
  464.     bar(1,getmaxy()-9,getmaxx(),getmaxy());
  465.     settextstyle(0,0,0);
  466.     settextjustify(LEFT_TEXT,BOTTOM_TEXT);
  467.     moveto(4,getmaxy()-2);
  468.     outtext("Enter text? ");
  469.     outtext(s);
  470.     setcolor(0);
  471. }
  472.  
  473. d_get_point(double *x, double *y, int *click)
  474. {
  475.     int i,c,ix,iy,oldmode;
  476.  
  477.     if (ismouse) {
  478.         undxy(mousecol(),mouserow(),x,y);
  479.         d_mousex = *x; d_mousey = *y;
  480.     } else {
  481.         *x = d_mousex;
  482.         *y = d_mousey;
  483.     }
  484.     *click = 0;
  485.     if (kbhit()) {
  486.         oldmode = d_imde;
  487.         c = text_inkey();
  488.         c = tolower(c);
  489.         switch (c) {
  490.           case 'l': /* line */
  491.             d_imde = 2;  break;
  492.           case 'b': /* box */
  493.             d_imde = 3;  break;
  494.           case 't': /* text */
  495.             d_imde = 1;  boxed_text = false; break;
  496.           case 'o': /* boxed text */
  497.             d_imde = 1;
  498.             boxed_text = true; break;
  499.           case 'f': /* finer grid */
  500.             gridstep = gridstep / 10; break;
  501.           case 'g': /* greater grid */
  502.             gridstep *= 10; break;
  503.           case ereturn: /* return, finished */
  504.           case eescape:
  505.             *click = 3; break;
  506.           case 'u':  /* pen up */
  507.             *click = 2; break;
  508.           case 'd': /* pen down */
  509.           case 'c': /* click */
  510.             *click = 1; break;
  511.           case eup: /* Move cursor up 1 grid step */
  512.             *y += gridstep; break;
  513.           case edown:
  514.             *y -= gridstep; break;
  515.           case eright:
  516.             *x += gridstep; break;
  517.           case eleft:
  518.             *x -= gridstep; break;
  519.         }
  520.         if (oldmode!=d_imde) *click = 2;
  521.     }
  522.     if (ismouse) {
  523.         i = mouseclick();
  524.         if (i>0) *click = i;
  525.         undxy(mousecol(),mouserow(),x,y);
  526.     } else {
  527.         gridit(x,y);
  528.     }
  529.     if (*x != d_mousex || *y != d_mousey) {
  530.         if (ismouse) {
  531.             dxy(d_mousex,d_mousey,&ix,&iy);
  532.             mouseloc(ix,iy);
  533.         } else {
  534.             d_cursor_toggle();
  535.             d_mousex = *x;
  536.             d_mousey = *y;
  537.             d_cursor_toggle();
  538.         }
  539.     }
  540. }
  541. cross_hair(double x,double y)
  542. {
  543.     int ix,iy;
  544.     dxy(x,y,&ix,&iy);
  545.     moveto(ix,iy-10);
  546.     lineto(ix,iy+10);
  547.     moveto(ix-10,iy);
  548.     lineto(ix+10,iy);
  549. }
  550. d_close()
  551. {
  552.     stop;gon;
  553.     if (ingraphmode == false) return;
  554.     g_flush();
  555.     d_message("Press <RETURN> to continue");
  556.     lastline[0] = 0;
  557.     if (kbhit()) getch();
  558.     wait_for_return();
  559.     ingraphmode = false;
  560.     restorecrtmode();
  561. }
  562. /*---------------------------------------------------------------------------*/
  563. d_set_line_cap(int i)
  564. {
  565.     i++;
  566. }
  567. /*---------------------------------------------------------------------------*/
  568. d_set_line_join(int i)
  569. {
  570.     i++;
  571. }
  572. /*---------------------------------------------------------------------------*/
  573. d_set_line_miterlimit(double d)
  574. {
  575.     i++;
  576. }
  577. /*---------------------------------------------------------------------------*/
  578. d_set_line_width(double w)
  579. {
  580.     stop;
  581.     d_lwidth = 1;
  582.     if (w>.099) d_lwidth = 3;
  583.     setlinestyle(d_lstyle,d_pat,d_lwidth);
  584.     gerr();goff;
  585. }
  586. /*---------------------------------------------------------------------------*/
  587. d_set_line_styled(double dd)
  588. {}
  589. d_set_line_style(char *s)
  590. {
  591.     static char *defline[] = {"","","12","41","14","92",
  592.     "1282","9229","4114","54"};
  593.     int i, j, nblack, nwhite, pat;
  594.     char *ss;
  595.     stop;gon;
  596.  
  597.     if (strlen(s)==1)  s = defline[*s-'0'];
  598.     if (strcmp(s,"")==0) {
  599.         d_lstyle = SOLID_LINE;
  600.         d_pat = 0;
  601.         setlinestyle(d_lstyle,0,d_lwidth);
  602.     } else {
  603.         ss = s;
  604.         pat = 0;                 /* make a 16 bit pattern from digits */
  605.         for (i=15; i>=0;) {
  606.         nblack = *s - '0';
  607.         s++;
  608.         for (j=0; j<nblack; j++) {
  609.             pat = pat | (1L << i);
  610.             i--;
  611.         }
  612.         if (*s == 0)  s = ss;   /* if odd number of digits, repeat */
  613.         nwhite = *s - '0';
  614.         s++;
  615.         i = i - nwhite;
  616.         if (*s == 0)  s = ss;
  617.         }
  618.         d_lstyle = USERBIT_LINE;
  619.         d_pat = pat;
  620.         setlinestyle(d_lstyle,pat,d_lwidth);
  621.     }
  622.     gerr();goff;
  623. }
  624. /*---------------------------------------------------------------------------*/
  625. d_fill()
  626. {
  627. }
  628. /*---------------------------------------------------------------------------*/
  629. d_fill_ary(int nwk,double (*wkx)[],double (*wky)[])
  630. {
  631.     int i;
  632. /*  fprintf(psfile,"%g %g moveto \n",(*wkx)[0],(*wky)[0]);
  633.     for (i=1;i<nwk;i++)
  634.         fprintf(psfile,"%g %g l \n",(*wkx)[i],(*wky)[i]);
  635. */
  636. }
  637. d_line_ary(int nwk,double (*wkx)[],double (*wky)[])
  638. {
  639.     int i;
  640.     stop;gon;
  641.     dxy( (*wkx)[0], (*wky)[0], &ix, &iy);
  642.     moveto(ix,iy);
  643.     for (i=1;i<nwk;i++) {
  644.         dxy( (*wkx)[i], (*wky)[i], &ix, &iy);
  645.         lineto(ix,iy);
  646.     }
  647.     gerr();goff;
  648. }
  649. /*---------------------------------------------------------------------------*/
  650. d_stroke()
  651. {
  652. }
  653. /*---------------------------------------------------------------------------*/
  654. d_clip()
  655. {
  656. }
  657. /*---------------------------------------------------------------------------*/
  658. d_set_matrix(double newmat[3][3])
  659. {
  660. }
  661. /*---------------------------------------------------------------------------*/
  662. d_move(double zx,double zy)
  663. {
  664. }
  665. #ifdef DJ                                       /* a.r */
  666. d_move_really(float zx, float zy)
  667. {
  668.     moveto(sx(zx),sy(zy));
  669. }
  670. int draw_circle(void)
  671. {
  672.     circle(getx(), gety(), 4);
  673. }
  674. #endif
  675. /*---------------------------------------------------------------------------*/
  676. d_reverse()     /* reverse the order of stuff in the current path */
  677. {
  678. }
  679. /*---------------------------------------------------------------------------*/
  680. d_closepath()
  681. {
  682.     g_line(g.closex,g.closey);
  683. }
  684. /*---------------------------------------------------------------------------*/
  685. int dunx1,dunx2,duny1,duny2;
  686. d_unline()
  687. {
  688.      setcolor(getwhite());
  689.     moveto(dunx1,duny1);
  690.     lineto(dunx2,duny2);
  691. }
  692. d_zzline(double cx,double cy,double zx,double zy)
  693. {
  694.     static int ux,uy,ix,iy;
  695.     dxy(cx,cy,&ux,&uy);
  696.     dunx1 = ux; duny1 = uy;
  697.     dxy(zx,zy,&ix,&iy);
  698.      setcolor(0);
  699.     moveto(ux,uy);
  700.     lineto(ix,iy);
  701.     dunx2 = ix; duny2 = iy;
  702. }
  703.  
  704. d_line(double zx,double zy)
  705. {
  706.     static int ux,uy;
  707.     if (g.xinline==false) {
  708.         dxy(g.curx,g.cury,&ux,&uy);
  709.         moveto(ux,uy);
  710.         dunx1 = ux; duny1 = uy;
  711.     }
  712.     dxy(zx,zy,&ix,&iy);
  713.     lineto(ix,iy);
  714.     dunx2 = ix; duny2 = iy;
  715. }
  716. /*---------------------------------------------------------------------------*/
  717. d_clear()
  718. {
  719.     double width,height;
  720.     int x1,y1,x2,y2;
  721.     width = g.userwidth;
  722.     height = g.userheight;
  723.     stop;
  724.     d_lstyle = SOLID_LINE;
  725.     d_pat = 0;
  726.     d_lwidth = 1;
  727.     setgraphmode(d_graphmode);
  728.  
  729.     /* now draw bounding box of screen */
  730.     x1 = 0;
  731.     y1 = d_maxy-height*d_yscale -1;
  732.     x2 = width*d_xscale+2;
  733.     y2 = d_maxy+1;
  734.     setfillstyle(1,getwhite());
  735.     bar(x1,y1,x2,y2);
  736.     setcolor(BLACK);
  737.     goff;
  738. }
  739. /*---------------------------------------------------------------------------*/
  740. d_flush()
  741. {
  742. }
  743. /*---------------------------------------------------------------------------*/
  744. int polar_xy(double r, double angle, double *dx, double *dy);
  745. int xy_polar(double dx,double dy,double *radius,double *angle);
  746.  
  747. #ifdef OLDARC   /* old arc/narc routines used BGI and draw weird things a.r.*/
  748. d_arcto(dbl x1,dbl y1,dbl x2,dbl y2,dbl rrr)
  749. {
  750.     double x0,y0,r1,a1,r2,a2,r3,a3,a4,r5,sx,sy,ex,ey;
  751.     double bx1,by1,bx2,by2,dist,neg;
  752.     g_get_xy(&x0,&y0);
  753.     xy_polar(x1-x0,y1-y0,&r1,&a1);
  754.     xy_polar(x2-x1,y2-y1,&r2,&a2);
  755.     neg = 1;
  756.     a4 = (180-a2+a1);
  757.     a3 = a2 + (a4/2);
  758.     if ((a4/2)>90 && (a4/2)<180 ) neg = -1;
  759.     if ((a4/2)<0 && (a4/2)>-90 ) neg = -1;
  760.     r3 = neg*rrr/(tan((pi/180)*a4/2));
  761.     dbg gprint("rrr %g a4/2 %g t=%g a2=%g a1=%g r1=%g r2=%g r3=%g \n",rrr,a4/2,tan(a4/2),a2,a1,r1,r2,r3);
  762.     polar_xy(-r3,a1,&sx,&sy); sx += x1; sy += y1;
  763.     polar_xy(r3,a2,&ex,&ey); ex += x1; ey += y1;
  764.     g_line(sx,sy);
  765.     dist = sqrt(pow(ex-sx,2) + pow(ey-sy,2));
  766.     polar_xy(r1+ dist/2.5-r3,a1,&bx1,&by1); bx1 += x0; by1 += y0;
  767.     polar_xy(-r2+ -dist/2.5+r3,a2,&bx2,&by2); bx2 += x2; by2 += y2;
  768.     g_bezier(bx1,by1,bx2,by2,ex,ey);
  769.     g_line(x2,y2);
  770. }
  771. /*---------------------------------------------------------------------------*/
  772.  
  773. /* makes arc/narc in gle_vga/cgle work like gle_ps/Ghostscript a.r.     */
  774. /* but does not work in a rotate environment                            */
  775. void bgi_ellipse(int center_x,    int center_y,
  776.          int start_angle, int end_angle,
  777.          int radius_x,    int radius_y   )
  778. {
  779.     int st_angle;                   /* angles must be >= 0 */
  780.     int e_angle;
  781.     int n_s=0, sign_s=0, n_e=0, sign_e=0;
  782.  
  783.     n_s = abs(start_angle/360);
  784.     if (start_angle < 0)
  785.         {
  786.         sign_s = 1;
  787.         n_s += 1;
  788.         }
  789.     else
  790.         sign_s = -1;
  791.     st_angle = start_angle + sign_s * n_s * 360;
  792.  
  793.     n_e = abs(end_angle/360);
  794.     if (end_angle < 0)
  795.         {
  796.         sign_e = 1;
  797.         n_e += 1;
  798.         }
  799.     else
  800.         sign_e = -1;
  801.  
  802.     e_angle = end_angle + sign_e * n_e * 360;
  803.     if (    sign_s == -1 && sign_e == -1 &&  end_angle - start_angle >= 360
  804.          || sign_s ==  1 && sign_e == -1 &&  end_angle - start_angle >= 360
  805.          || sign_s ==  1 && sign_e ==  1 &&  start_angle < end_angle && end_angle - start_angle >= 360  
  806.        )
  807.         ellipse( center_x,      center_y,
  808.              0,             360,
  809.              radius_x,      radius_y   );
  810.     ellipse( center_x,      center_y,
  811.          st_angle,      e_angle,
  812.          radius_x,      radius_y   );
  813. }
  814. /*---------------------------------------------------------------------------*/
  815. d_arc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)        /* changed, a.r. */
  816. {
  817.     static int ixr,iyr,icx,icy;
  818.     double ux,uy,z;
  819.     dxy(cx,cy,&icx,&icy);
  820.     rxy(r,r,&ixr,&iyr);
  821.     /* if (t1>t2) {z = t1; t1 = t2; t2 = z;} */
  822.     /* arc(icx,icy,(int) t1, (int) t2, ixr); */
  823.     bgi_ellipse(icx,icy,(int) t1, (int) t2, ixr, iyr);
  824. }
  825. /*---------------------------------------------------------------------------*/
  826. d_narc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)       /* changed, a.r. */ 
  827. {
  828.     static int ixr,iyr,icx,icy;
  829.     double ux,uy,z;
  830.     dxy(cx,cy,&icx,&icy);
  831.     rxy(r,r,&ixr,&iyr);
  832.     /* if (t1>t2) {z = t1; t1 = t2; t2 = z;} */
  833.     z = t1; t1 = t2; t2 = z;      /* very tricky :^) */
  834.     /* arc(icx,icy,(int) t1, (int) t2, ixr);*/
  835.     bgi_ellipse(icx,icy,(int) t1, (int) t2, ixr, iyr);
  836. }
  837.  
  838. #else   /* new arc/narc routines from easydev.c */
  839.  
  840. #define CSTEP (360/6)
  841. df_arcto(dbl x1,dbl y1,dbl x2,dbl y2,dbl rrr)
  842. {
  843.     double x0,y0,r1,a1,r2,a2,r3,a3,a4,r5,sx,sy,ex,ey;
  844.     double bx1,by1,bx2,by2,dist,neg;
  845.     g_get_xy(&x0,&y0);
  846.     xy_polar(x1-x0,y1-y0,&r1,&a1);
  847.     xy_polar(x2-x1,y2-y1,&r2,&a2);
  848.     neg = 1;
  849.     a4 = (180-a2+a1);
  850.     a3 = a2 + (a4/2);
  851.     if ((a4/2)>90 && (a4/2)<180 ) neg = -1;
  852.     if ((a4/2)<0 && (a4/2)>-90 ) neg = -1;
  853.     r3 = neg*rrr/(tan((pi/180)*a4/2));
  854.     polar_xy(-r3,a1,&sx,&sy); sx += x1; sy += y1;
  855.     polar_xy(r3,a2,&ex,&ey); ex += x1; ey += y1;
  856.     g_line(sx,sy);
  857.     dist = sqrt((ex-sx)*(ex-sx) + (ey-sy)*(ey-sy));
  858.     polar_xy(r1+ dist/2.5-r3,a1,&bx1,&by1); bx1 += x0; by1 += y0;
  859.     polar_xy(-r2+ -dist/2.5+r3,a2,&bx2,&by2); bx2 += x2; by2 += y2;
  860.     g_bezier(bx1,by1,bx2,by2,ex,ey);
  861.     g_line(x2,y2);
  862. }
  863. df_arc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  864. {
  865.     /* circle from t1 to t2, lets use 6 bezier's for a circle */
  866.     double stz;
  867.     int nst,i;
  868.  
  869.     for (;t2<t1;)
  870.           t2 = t2 + 360;
  871.  
  872.     nst = floor((t2-t1)/CSTEP)+1;
  873.     stz = (t2-t1) / nst;
  874.     for (i=1;i<=nst;i++)
  875.         xdf_barc(r,t1+stz*(i-1),t1+stz*i,cx,cy);
  876. }
  877. xdf_barc(double r,dbl t1,dbl t2,dbl cx,dbl cy)
  878. {
  879.     double rx1,ry1,rx2,ry2,d,dx1,dy1,dx2,dy2;
  880.  
  881.     polar_xy(r,t1,&rx1,&ry1);
  882.     polar_xy(r,t2,&rx2,&ry2);
  883.     d = sqrt( (rx2-rx1)*(rx2-rx1) + (ry2-ry1)*(ry2-ry1));
  884.     polar_xy(d/3,t1+90,&dx1,&dy1);
  885.     polar_xy(d/3,t2-90,&dx2,&dy2);
  886.     if (g.inpath) {
  887.         g_line(rx1+cx,ry1+cy);
  888.         g_bezier(rx1+cx+dx1,ry1+cy+dy1
  889.             ,rx2+cx+dx2,ry2+cy+dy2,rx2+cx,ry2+cy);
  890.     } else {
  891.         g_move(rx1+cx,ry1+cy);
  892.         g_bezier(rx1+cx+dx1,ry1+cy+dy1
  893.             ,rx2+cx+dx2,ry2+cy+dy2,rx2+cx,ry2+cy);
  894.         g_move(cx,cy);
  895.     }
  896. }
  897.  
  898. d_arcto(dbl x1,dbl y1,dbl x2,dbl y2,dbl rrr)
  899. {
  900.     df_arcto(x1,y1,x2,y2,rrr);
  901. }
  902. /*---------------------------------------------------------------------------*/
  903. d_arc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  904. {        
  905.     df_arc(r,t1,t2,cx,cy);
  906. }
  907. /*---------------------------------------------------------------------------*/
  908. d_narc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  909. {
  910.     /* swap t1 and t2 */
  911.     df_arc(r,t2,t1,cx,cy);
  912. }
  913. /*---------------------------------------------------------------------------*/
  914. #endif /* OLDARC */
  915.  
  916. /*---------------------------------------------------------------------------*/
  917. d_box_fill(dbl x1, dbl y1, dbl x2, dbl y2)
  918. {
  919.     int v[8];
  920.     dxy(x1,y1,&v[0],&v[1]);
  921.     dxy(x2,y1,&v[2],&v[3]);
  922.     dxy(x2,y2,&v[4],&v[5]);
  923.     dxy(x1,y2,&v[6],&v[7]);
  924.     fillpoly(4,v);
  925. }
  926. d_box_stroke(dbl x1, dbl y1, dbl x2, dbl y2)
  927. {
  928.     static int ix1,iy1,ix2,iy2,ix3,iy3,ix4,iy4;
  929.     static int ii;
  930.     stop;gon;
  931.     dxy(x1,y1,&ix1,&iy1);
  932.     dxy(x2,y1,&ix2,&iy2);
  933.     dxy(x2,y2,&ix3,&iy3);
  934.     dxy(x1,y2,&ix4,&iy4);
  935.     moveto(ix1,iy1);
  936.     lineto(ix2,iy2);
  937.     lineto(ix3,iy3);
  938.     lineto(ix4,iy4);
  939.     lineto(ix1,iy1);
  940.     goff;
  941. }
  942. /*---------------------------------------------------------------------------*/
  943. d_circle_stroke(double zr)
  944. {
  945.     static int ixr,iyr;
  946.     int ux,uy;
  947.     rxy(zr,zr,&ixr,&iyr);
  948.     dxy(g.curx,g.cury,&ux,&uy);
  949.     ellipse(ux,uy,0,360,ixr,iyr);
  950. }
  951. d_circle_fill(double zr)
  952. {
  953.     static int ixr,iyr;
  954.     int ux,uy;
  955.     dxy(g.curx,g.cury,&ux,&uy);
  956.     rxy(zr,zr,&ixr,&iyr);
  957.     fillellipse(ux,uy,ixr,iyr);
  958. }
  959. /*---------------------------------------------------------------------------*/
  960. d_bezier(dbl x1,dbl y1,dbl x2,dbl y2,dbl x3,dbl y3)
  961. {
  962.     double ax,bx,cx,ay,by,cy,dist;
  963.     double xxx,yyy,i,t,nstep,x0,y0;
  964.     g_get_xy(&x0,&y0);
  965.     dist = fabs(x3-x0) + fabs(y3-y0);
  966.     nstep = 12;
  967.     if (dist<1) nstep = 7;
  968.     if (dist<.5) nstep = 3;
  969.     if (dist<.1) {
  970.         g_line(x3,y3);
  971.         return;
  972.     }
  973.     cx = (x1-x0)*3;
  974.     bx = (x2-x1)*3-cx;
  975.     ax = x3-x0-cx-bx;
  976.     cy = (y1-y0)*3;
  977.     by = (y2-y1)*3-cy;
  978.     ay = y3-y0-cy-by;
  979.     for (i=0;i<=nstep;i++) {
  980.         t = i/nstep;
  981.         xxx = ax*pow(t,3.0) + bx*t*t + cx*t + x0;
  982.         yyy = ay*pow(t,3.0) + by*t*t + cy*t + y0;
  983.         g_line(xxx,yyy);
  984.     }
  985. }
  986. /*
  987. /* d_bezier(dbl zx1,dbl zy1,dbl zx2,dbl zy2,dbl zx3,dbl zy3)
  988. /* {
  989. /*  int32  ax,bx,cx,ay,by,cy,dist;
  990. /*  int32 xxx,yyy,i,t,nstep;
  991. /*  int32 t2,t3;
  992. /*  int x0,y0,x1,y1,x2,y2,x3,y3;
  993. /*  double zx0,zy0;
  994. /*  g_get_xy(&zx0,&zy0);
  995. /*
  996. /*  dxy(zx1,zy1,&x1,&y1);
  997. /*  dxy(zx2,zy2,&x2,&y2);
  998. /*  dxy(zx3,zy3,&x3,&y3);
  999. /*  dxy(zx0,zy0,&x0,&y0);
  1000. /*
  1001. /*  x0 *= 1; y0 *= 1;
  1002. /*  x1 *= 1; y1 *= 1;
  1003. /*  x2 *= 1; y2 *= 1;
  1004. /*  x3 *= 1; y3 *= 1;
  1005. /*  nstep = 20;
  1006. /*  cx = (x1-x0)*3;
  1007. /*  bx = (x2-x1)*3-cx;
  1008. /*  ax = x3-x0-cx-bx;
  1009. /*  cy = (y1-y0)*3;
  1010. /*  by = (y2-y1)*3-cy;
  1011. /*  ay = y3-y0-cy-by;
  1012. /*  t3 = 0;
  1013. /*  for (i=0; i<=100; i += 10) {
  1014. /*      t = i ;
  1015. /*      t2 = (i*i)/100l;
  1016. /*      t3 = (t2*i)/100l;
  1017. /*      xxx = (ax*t3) + (bx*t2) + (cx*t) + ((int32 ) x0)*100l;
  1018. /*      yyy = (ay*t3) + (by*t2) + (cy*t) + ((int32 ) y0)*100l;
  1019. /*      lineto((int) (xxx/100l),(int) (yyy/100l));
  1020. /*  }
  1021. /* }
  1022. */
  1023. /*---------------------------------------------------------------------------*/
  1024. d_set_color(int32 f)
  1025. {
  1026.     int i;
  1027.     colortyp  cc;
  1028.     stop;gon;
  1029.     cc.l = f;
  1030.     i = 0;
  1031.     if (cc.b[B_R]>10 && cc.b[B_G]>10 && cc.b[B_B]>10) i = DARKGRAY;
  1032.     if (cc.b[B_R]>60 && cc.b[B_G]>60 && cc.b[B_B]>60) i = LIGHTGRAY;
  1033.     if (cc.b[B_R]>100) i = LIGHTRED;
  1034.     if (cc.b[B_B]>100) i = LIGHTBLUE;
  1035.     if (cc.b[B_G]>100) i = LIGHTGREEN;
  1036.     if (cc.b[B_R]>100 && cc.b[B_G]>100) i = YELLOW;
  1037.     if (cc.b[B_G]>100 && cc.b[B_B]>100) i = CYAN; 
  1038.     if (cc.b[B_R]>30 && cc.b[B_B]>100) i = MAGENTA;
  1039.     if (cc.b[B_R]>100 && cc.b[B_G]>100 && cc.b[B_B]>100) i = LIGHTGRAY;
  1040.     if (cc.b[B_R]<10 && cc.b[B_G]<10 && cc.b[B_B]<10) i = BLACK; 
  1041.     if (cc.b[B_R]>250 && cc.b[B_G]>250 && cc.b[B_B]>250) i = WHITE;
  1042.     setcolor(i); goff;
  1043. }
  1044. d_set_fill(int32 f)
  1045. {
  1046.     int i, j;
  1047.     colortyp  cc;
  1048.     int ufstyle;
  1049.     static char patterns[][8]={
  1050.         {  24,   0,   0, 129, 129,   0,   0,  24 },     /* GRID5  */
  1051.         {  60,  24, 129, 195, 195, 129,  24,  60 },     /* GRID4  */
  1052.         { 231, 219, 189, 126, 126, 189, 219, 231 },     /* GRID   */
  1053.         { 201, 156,  62,  62, 156, 201, 227, 227 },     /* GRID3  */
  1054.         { 254, 253, 251, 247, 239, 223, 191, 127 },     /* Shade  */
  1055.         { 252, 249, 243, 231, 207, 159,  63, 126 },     /* Shade2 */
  1056.         { 238, 221, 187, 119, 238, 221, 187, 119 },     /* Shade1 */
  1057.         { 124, 248, 241, 227, 199, 143,  31, 62 }       /* Shade3 */
  1058.         };
  1059.  
  1060.     stop;gon;
  1061.     cc.l = f;
  1062.     i = j = 0;
  1063.     if (cc.b[B_F] == 1){    /* colours */
  1064.         if (cc.b[B_R]>=10 && cc.b[B_G]>=10 && cc.b[B_B]>=10) i = DARKGRAY;
  1065.         if (cc.b[B_R]>60 && cc.b[B_G]>60 && cc.b[B_B]>60) i = LIGHTGRAY;
  1066.         if (cc.b[B_R]>100) i = LIGHTRED;
  1067.         if (cc.b[B_B]>100) i = LIGHTBLUE;
  1068.         if (cc.b[B_G]>100) i = LIGHTGREEN;
  1069.         if (cc.b[B_R]>100 && cc.b[B_G]>100) i = YELLOW;
  1070.         if (cc.b[B_G]>100 && cc.b[B_B]>100) i = CYAN; 
  1071.         if (cc.b[B_R]>30 && cc.b[B_B]>100) i = MAGENTA;
  1072.         if (cc.b[B_R]>100 && cc.b[B_G]>100 && cc.b[B_B]>100) i = LIGHTGRAY;
  1073.         if (cc.b[B_R]<10 && cc.b[B_G]<10 && cc.b[B_B]<10) i = BLACK; 
  1074.         if (cc.b[B_R]>250 && cc.b[B_G]>250 && cc.b[B_B]>250) i = WHITE;
  1075.         d_fillcolor = i;
  1076.            }
  1077.     if (cc.b[B_F] == 2){    /* grids and shades */
  1078.         if (cc.b[B_R]==0x00 && cc.b[B_G]==0x20 && cc.b[B_B]==0x20) {
  1079.             j = USER_FILL;  /* GRID */
  1080.             ufstyle = 2;
  1081.             }
  1082.         if (cc.b[B_R]==0x04 && cc.b[B_G]==0x0f && cc.b[B_B]==0x0f) {
  1083.             j = 11;         /* GRID1 */
  1084.             ufstyle = -1;
  1085.             }
  1086.         if (cc.b[B_R]==0x00 && cc.b[B_G]==0x10 && cc.b[B_B]==0x10) {
  1087.             j = USER_FILL;  /* GRID2 */
  1088.             ufstyle = 2;
  1089.             }
  1090.         if (cc.b[B_R]==0x05 && cc.b[B_G]==0x20 && cc.b[B_B]==0x20) {
  1091.             j = USER_FILL;  /* GRID3 */
  1092.             ufstyle = 3;
  1093.             }
  1094.         if (cc.b[B_R]==0x10 && cc.b[B_G]==0x40 && cc.b[B_B]==0x40) {
  1095.             j = USER_FILL;  /* GRID4 */
  1096.             ufstyle = 1;
  1097.             }
  1098.         if (cc.b[B_R]==0x20 && cc.b[B_G]==0x60 && cc.b[B_B]==0x60) {
  1099.             j = USER_FILL;  /* GRID5 */
  1100.             ufstyle = 0;
  1101.             }
  1102.         if (cc.b[B_R]==0x00 && cc.b[B_G]==0x00 && cc.b[B_B]==0x20) {
  1103.             j = USER_FILL;  /* SHADE */
  1104.             ufstyle = 4;
  1105.             }
  1106.         if (cc.b[B_R]==0x04 && cc.b[B_G]==0x00 && cc.b[B_B]==0x0C) {
  1107.             j = USER_FILL;  /* SHADE1 */
  1108.             ufstyle = 6;
  1109.             }
  1110.         if (cc.b[B_R]==0x00 && cc.b[B_G]==0x00 && cc.b[B_B]==0x10) {
  1111.             j = USER_FILL;  /* SHADE2 */
  1112.             ufstyle = 5;
  1113.             }
  1114.         if (cc.b[B_R]==0x05 && cc.b[B_G]==0x00 && cc.b[B_B]==0x20) {
  1115.             j = USER_FILL;  /* SHADE3 */
  1116.             ufstyle = 7;
  1117.             }
  1118.         if (cc.b[B_R]==0x10 && cc.b[B_G]==0x00 && cc.b[B_B]==0x40) {
  1119.             j = SLASH_FILL; /* SHADE4 */
  1120.             ufstyle = -1;
  1121.             }
  1122.         if (cc.b[B_R]==0x20 && cc.b[B_G]==0x00 && cc.b[B_B]==0x60) {
  1123.             j=LTSLASH_FILL; /* SHADE5 */
  1124.             ufstyle = -1;
  1125.             }
  1126.  
  1127.         d_fillstyle = j;
  1128.         if (ufstyle != -1)
  1129.             setfillpattern( &patterns[ufstyle][0], WHITE );
  1130.         setfillstyle(d_fillstyle, WHITE );
  1131.            }
  1132.     else
  1133.            {
  1134.         d_fillstyle = SOLID_FILL;
  1135.         setfillstyle(d_fillstyle,d_fillcolor);
  1136.            }
  1137.     goff;
  1138. }
  1139. /*---------------------------------------------------------------------------*/
  1140. d_beginclip()
  1141. {
  1142. }
  1143. d_endclip()
  1144. {
  1145. }
  1146. struct char_data {float wx,wy,x1,y1,x2,y2; };
  1147. int font_get_chardata(struct char_data **cd, int ff, int cc);
  1148. /*---------------------------------------------------------------------------*/
  1149. int safnt;
  1150. int simple_char(int cc);
  1151. d_char(int font, int cc)
  1152. {
  1153.     static struct char_data cd;
  1154.     static int ix1,ix2,iy1,iy2;
  1155.     static int ux,uy;
  1156.     char ss[2];
  1157.  
  1158.     ss[0] = cc;
  1159.     ss[1] = 0;
  1160.     if (safnt==0) safnt = pass_font("PLSR");
  1161.     if (font!=82 && font>7) {
  1162.         my_char(font,cc);
  1163.         return;
  1164.     }
  1165.     if (gunit) simple_char(cc);
  1166.     else  my_char(safnt,cc);
  1167. }
  1168.  
  1169. int pass_font(char *s);
  1170. int draw_char_fixed(char *s);
  1171. int get_char_pcode(int ff, int cc, char **pp);
  1172. simple_char(int cc)
  1173. {
  1174.     char *pp;
  1175.     get_char_pcode(safnt,cc,&pp);
  1176.     draw_char_fixed(pp);
  1177. }
  1178. int frxi(char **s);
  1179. draw_char_fixed(char *s)
  1180. {
  1181.     int ux,uy,cx,cy,x1,y1,x2,y2,lx,ly;
  1182.     int32 xsclm,ysclm,xscld,yscld;
  1183.     double ox,oy;
  1184.     dxy(g.curx,g.cury,&ux,&uy);
  1185.     xsclm = g.fontsz*d_xscale; xscld = 1000;
  1186.     ysclm = g.fontsz*d_yscale; yscld = 1000;
  1187.     while (*s!=15) {
  1188.       switch (*s++) {
  1189.         case 1:
  1190.         cx = frxi(&s); cy = frxi(&s);
  1191.         moveto(ux + (cx*xsclm)/xscld, uy - (cy*ysclm)/yscld );
  1192.         lx = cx; ly = cy;
  1193.         break;
  1194.         case 2:
  1195.         cx = cx + frxi(&s); cy = cy + frxi(&s);
  1196.         lineto(ux + (cx*xsclm)/xscld, uy - (cy*ysclm)/yscld );
  1197.         break;
  1198.         case 3:
  1199.         cx = cx + frxi(&s); cy = cy + frxi(&s);
  1200.         x1 = cx; y1 = cy;
  1201.         cx = cx + frxi(&s); cy = cy + frxi(&s);
  1202.         x2 = cx; y2 = cy;
  1203.         cx = cx + frxi(&s); cy = cy + frxi(&s);
  1204.         g_bezier(x1,y1,x2,y2,cx,cy);
  1205.         break;
  1206.         case 4:
  1207.         lineto(ux + (lx*xsclm)/xscld, uy - (ly*ysclm)/yscld );
  1208.         break;
  1209.         case 5:
  1210.         case 6:
  1211.         case 7:
  1212.         case 8:
  1213.         break;
  1214.         case 0: /* no char in this font */
  1215.         goto abort;
  1216.         default:
  1217.         gprint("Error in mychar pcode %d \n",*s++);
  1218.         goto abort;
  1219.       }
  1220.  
  1221.     }
  1222. abort:;
  1223. }
  1224.